package com.demoProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyUtil {
    /*
     * 作用：给star的对象，做一个代理
     * 
     * 
     */

     public static Star createProxy(BigStar bigStar) {
        
        Star star = (Star) Proxy.newProxyInstance(ProxyUtil.class.getClassLoader(),
            new Class[] {Star.class},
            new InvocationHandler(){
                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException{
                    if("sing".equals(method.getName())){
                        System.out.println("准备话筒，收钱");
                    }else if("eating".equals(method.getName())){
                        System.out.println("准备食物，干饭");
                    }
                    

                    
                    return method.invoke(bigStar, args);
                }
            
            }
        );
    return star;
                    
    }
}
